@inherits AppComponentBase

<section>
    <BitStack HorizontalAlign="BitAlignment.Center">
        @if (showConfirmation is false)
        {
            <EditForm Model="sendModel" OnValidSubmit="WrapHandled(SendToken)" novalidate class="max-width">
                <AppDataAnnotationsValidator />

                <BitStack FillContent>
                    @if (PhoneNumber is not null)
                    {
                        <BitTextField Value="@PhoneNumber" ReadOnly NoValidate />
                    }

                    <BitTextField @bind-Value="sendModel.PhoneNumber"
                                  Type="BitInputType.Tel"
                                  Label="@Localizer[nameof(AppStrings.NewPhoneNumber)]"
                                  Placeholder="@Localizer[nameof(AppStrings.NewPhoneNumberPlaceholder)]" />
                    <ValidationMessage For="@(() => sendModel.PhoneNumber)" />

                    <BitButton IsLoading="isWaiting" ButtonType="BitButtonType.Submit">
                        @Localizer[nameof(AppStrings.Submit)]
                    </BitButton>

                    <div>
                        @Localizer[nameof(AppStrings.ConfirmMessageInProfile)]
                        <BitButton ButtonType="BitButtonType.Button"
                                   Variant="BitVariant.Text"
                                   OnClick="() => showConfirmation = true">
                            @Localizer[nameof(AppStrings.Confirm)]
                        </BitButton>
                    </div>
                    <br />
                </BitStack>
            </EditForm>
        }
        else
        {
            <BitText Typography="BitTypography.Subtitle1" Gutter>
                @Localizer[nameof(AppStrings.ConfirmPhoneSubtitle)]
                <br />
                @Localizer[nameof(AppStrings.ConfirmPhoneMessage)]
            </BitText>

            <EditForm Model="changeModel" OnValidSubmit="WrapHandled(ChangePhoneNumber)" novalidate class="max-width">
                <AppDataAnnotationsValidator />

                <BitStack FillContent>
                    <BitTextField @bind-Value="changeModel.PhoneNumber"
                                  IsEnabled="isPhoneNumberUnavailable"
                                  Type="BitInputType.Tel"
                                  Label="@Localizer[nameof(AppStrings.PhoneNumber)]"
                                  Placeholder="@Localizer[nameof(AppStrings.PhoneNumberPlaceholder)]" />
                    <ValidationMessage For="@(() => changeModel.PhoneNumber)" />

                    <BitOtpInput @bind-Value="changeModel.Token"
                                 AutoFocus
                                 Length="6"
                                 Size="BitSize.Large"
                                 Type="BitInputType.Number"
                                 OnFill="WrapHandled(ChangePhoneNumber)"
                                 Label="@Localizer[nameof(AppStrings.PhoneToken)]" />
                    <ValidationMessage For="@(() => changeModel.Token)" />

                    <BitButton IsLoading="isWaiting" ButtonType="BitButtonType.Submit">
                        @Localizer[nameof(AppStrings.PhoneTokenConfirmButtonText)]
                    </BitButton>

                    <div>
                        <BitButton ButtonType="BitButtonType.Button"
                                   Variant="BitVariant.Text"
                                   IconName="@BitIconName.Back"
                                   OnClick="GoBack">
                            @Localizer[nameof(AppStrings.GoBack)]
                        </BitButton>
                    </div>
                </BitStack>
            </EditForm>

            @if (isPhoneNumberUnavailable is false)
            {
                <BitText Typography="BitTypography.Body1" Gutter>
                    @Localizer[nameof(AppStrings.NotReceivedPhoneMessage)]
                </BitText>

                <BitButton IsLoading="isWaiting"
                           ButtonType="BitButtonType.Button"
                           Variant="BitVariant.Outline"
                           OnClick="WrapHandled(SendToken)">
                    @Localizer[nameof(AppStrings.ResendPhoneTokenButtonText)]
                </BitButton>
            }
            <br />
        }
    </BitStack>
</section>
